package com.xinxin.leetcode.problem541;

/**
 * @author ShiXinXin
 * @date 2020-01-17 9:46
 */
public class Solution {
    private void swap(char[] chs, int begin, int end) {
        while (begin < end) {
            char temp = chs[begin];
            chs[begin++] = chs[end];
            chs[end--] = temp;
        }
    }

    public String reverseStr(String s, int k) {
        char[] chs = s.toCharArray();
        for (int i = 0; i < chs.length; i += 2 * k) {
            swap(chs, i, Math.min(i + k - 1, chs.length - 1));
        }
        return new String(chs);
    }

    public static void main(String[] args) {
        System.out.println(new Solution().reverseStr("a", 2));
    }
}
